package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.Order;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.operate.parameter.req.OrderPayCallBackReq;
import com.ymatou.iapi.trading.operate.service.OrderPayCallBackCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.PaymentProxyCallService;
import com.ymttest.database.model.YmtAccountEntry;
import com.ymttest.database.sqlwapper.AccountDefaultWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.constant.ECode;

/**
 * 第三方支付定金回调通知接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_OrderPayCallBack {
	private static OrderPayCallBackReq orderPayCallBackBean;
	private static OrderPayCallBackCall orderPayCallBackCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("第三方支付定金回调通知接口");
	}

	@Before
	public void caseUp() {

		orderPayCallBackBean = new OrderPayCallBackReq();
		orderPayCallBackCall = new OrderPayCallBackCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(orderPayCallBackCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderPayCallBack_001() {
		Logger.start(true, "第三方支付,回调成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			Logger.comment("前置数据准备結束");

			DefaultWapper database = new DefaultWapper();

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO.setScale(2);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 查询支付指令
			HashMap paymentInstruction = new HashMap();

			paymentInstruction = new DefaultWapper()
					.selectPaymentInstructionByNewtradingId(String
							.valueOf(thirdTradingId));
			String trackId = (String) paymentInstruction.get("id");
			orderPayCallBackBean.setAppId("1");
			orderPayCallBackBean.setBizCode("3");
			orderPayCallBackBean.setCurrency("CNY");
			orderPayCallBackBean.setMemo("autotest");
			orderPayCallBackBean.setTradingId(String.valueOf(thirdTradingId));
			orderPayCallBackBean.setPaymentId("radamnumber");
			orderPayCallBackBean.setExternalPayerId("2088022137890789");
			// 此接口的价格不用传，因为接口不会按照这个参数进行支付。
			orderPayCallBackBean.setPayPrice("price");
			orderPayCallBackBean.setPayTime("2015-09-09T22:53:22");
			orderPayCallBackBean.setSignMethod("");
			orderPayCallBackBean.setTraceId(trackId);
			orderPayCallBackBean.setInstPaymentId("radamInstPaymentId");
			orderPayCallBackBean.setInternalUserId("internaluseid");
			orderPayCallBackBean.setExternalUserId("radamuserId");
			orderPayCallBackBean.setPayChannel("Alipay");
			orderPayCallBackBean.setPayType("type");
			orderPayCallBackBean.setVersion(1);
			// 发送请求
			orderPayCallBackCall.setData(orderPayCallBackBean);
			orderPayCallBackCall.callService();

			Logger.verifyEquals(ECode.SUCCESS, orderPayCallBackCall.getCode(),
					"验证Code");
			// 支付后金额
			Map act = new HashMap();
			act.put("bizno", String.valueOf(orderId));
			act.put("userId", userId);
			List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);

			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 2);
			m.put("TraddingId", orderId);
			m.put("ReceiveUserId", sellerId);
			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易状态表");
			Logger.verifyEquals(totalPrice,
					actinfos.get(0).getAmount()
							.divide(new BigDecimal(-1), 2, 4), "验证账户资金流水金额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_OrderPayCallBack_002() {
		Logger.start(false, "交易号为空,失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 买家付款
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			// 参数
			orderPayCallBackBean.setAppId("1");
			orderPayCallBackBean.setVersion(1);
			// 此接口的价格不用传，因为接口不会按照这个参数进行支付。
			orderPayCallBackBean.setPayPrice("price");
			orderPayCallBackBean.setCurrency("CNY");
			orderPayCallBackBean.setTraceId("123456");
			orderPayCallBackBean.setPayTime("2015-09-10 22:53:22");
			// 获取补款号
			orderPayCallBackBean.setTradingId("");
			orderPayCallBackBean.setPaymentId("radamnumber");
			orderPayCallBackBean.setExternalUserId("radamuserId");
			orderPayCallBackBean.setInstPaymentId("radamInstPaymentId");
			orderPayCallBackBean.setBizCode("1");
			//
			orderPayCallBackBean.setSignMethod("");

			// 发送请求
			orderPayCallBackCall.setData(orderPayCallBackBean);
			orderPayCallBackCall.callService();
			Logger.verifyEquals(ECode.FAILED400,
					orderPayCallBackCall.getCode(), "验证Code");
			Logger.verifyEquals(
					true,
					orderPayCallBackCall.getMsg().contains(
							ECode.ERROR400_MSG_10), "验证Msg"
							+ orderPayCallBackCall.getMsg());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_OrderPayCallBack_003() {
		Logger.start(false, "交易号不存在,回调失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 买家付款
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 接单
			new OrderCallService().acceptOrder(orderId, sellerId);

			Logger.comment("前置数据准备结束");
			orderPayCallBackBean.setAppId("1");
			orderPayCallBackBean.setBizCode("3");
			orderPayCallBackBean.setCurrency("CNY");
			orderPayCallBackBean.setMemo("autotest");
			orderPayCallBackBean.setTradingId("111111111111");
			orderPayCallBackBean.setPaymentId("radamnumber");
			// 此接口的价格不用传，因为接口不会按照这个参数进行支付。
			orderPayCallBackBean.setPayPrice("price");
			orderPayCallBackBean.setPayTime("2015-09-09T22:53:22");
			orderPayCallBackBean.setSignMethod("");
			orderPayCallBackBean.setTraceId("22222222222");
			orderPayCallBackBean.setInstPaymentId("radamInstPaymentId");
			orderPayCallBackBean.setInternalUserId("internaluseid");
			orderPayCallBackBean.setExternalUserId("radamuserId");
			orderPayCallBackBean.setPayChannel("Alipay");
			orderPayCallBackBean.setPayType("type");
			orderPayCallBackBean.setVersion(1);
			// 发送请求
			orderPayCallBackCall.setData(orderPayCallBackBean);
			orderPayCallBackCall.callService();
			Logger.verifyEquals(ECode.FAILED201,
					orderPayCallBackCall.getCode(), "验证Code");
			Logger.verifyEquals("Not Found paymentInstruction from tradingId:"
					+ orderPayCallBackBean.getTradingId(),
					orderPayCallBackCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_OrderPayCallBack_004() {
		Logger.start(false, "BizCode为空,失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					BigDecimal.ZERO, tradingId, payType);
			// 查询支付指令
			HashMap paymentInstruction = new HashMap();
			paymentInstruction = new DefaultWapper()
					.selectPaymentInstructionByNewtradingId(String
							.valueOf(thirdTradingId));
			String trackId = (String) paymentInstruction.get("id");
			orderPayCallBackBean.setAppId("1");
			// orderPayCallBackBean.setBizCode("3");
			orderPayCallBackBean.setCurrency("CNY");
			orderPayCallBackBean.setMemo("autotest");
			orderPayCallBackBean.setTradingId(String.valueOf(thirdTradingId));
			orderPayCallBackBean.setPaymentId("radamnumber");
			// 此接口的价格不用传，因为接口不会按照这个参数进行支付。
			orderPayCallBackBean.setPayPrice("price");
			orderPayCallBackBean.setPayTime("2015-09-09T22:53:22");
			orderPayCallBackBean.setSignMethod("");
			orderPayCallBackBean.setTraceId(trackId);
			orderPayCallBackBean.setInstPaymentId("radamInstPaymentId");
			orderPayCallBackBean.setInternalUserId("internaluseid");
			orderPayCallBackBean.setExternalUserId("radamuserId");
			orderPayCallBackBean.setPayChannel("Alipay");
			orderPayCallBackBean.setPayType("type");
			orderPayCallBackBean.setVersion(1);
			// 发送请求
			orderPayCallBackCall.setData(orderPayCallBackBean);
			orderPayCallBackCall.callService();
			Logger.verifyEquals(ECode.ERROR400, orderPayCallBackCall.getCode(),
					"验证Code");
			Logger.verifyEquals(true,
					orderPayCallBackCall.getMsg().contains("bizCode业务代码不能为空!"),
					"验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderPayCallBack_005() {
		Logger.start(true, "一笔交易里有多个订单,全款第三方支付宝支付,第三方支付通知成功");
		try {
			DefaultWapper database = new DefaultWapper();

			OrderCallService orderCallService = new OrderCallService();

			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			List<Order> orders = placeOrderResp.getOrderList();

			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal needPayAmount = placeOrderResp.getPayAmount();// 支付金额

			Logger.comment("前置数据准备结束");

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO.setScale(2);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 查询支付指令
			HashMap paymentInstruction = new HashMap();
			paymentInstruction = new DefaultWapper()
					.selectPaymentInstructionByNewtradingId(String
							.valueOf(thirdTradingId));

			String trackId = (String) paymentInstruction.get("id");

			orderPayCallBackBean.setAppId("1");
			orderPayCallBackBean.setBizCode("3");
			orderPayCallBackBean.setCurrency("CNY");
			orderPayCallBackBean.setMemo("autotest");
			orderPayCallBackBean.setTradingId(String.valueOf(thirdTradingId));
			orderPayCallBackBean.setPaymentId("radamnumber");
			// 此接口的价格不用传，因为接口不会按照这个参数进行支付。
			orderPayCallBackBean.setPayPrice("price");
			orderPayCallBackBean.setPayTime("2015-09-09T22:53:22");
			orderPayCallBackBean.setSignMethod("");
			orderPayCallBackBean.setTraceId(trackId);
			orderPayCallBackBean.setInstPaymentId("radamInstPaymentId");
			orderPayCallBackBean.setInternalUserId("internaluseid");
			orderPayCallBackBean.setExternalUserId("radamuserId");
			orderPayCallBackBean.setPayChannel("Alipay");
			orderPayCallBackBean.setPayType("type");
			orderPayCallBackBean.setVersion(1);
			// 发送请求
			orderPayCallBackCall.setData(orderPayCallBackBean);
			orderPayCallBackCall.callService();
			// 支付后金额
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(tradingId));
			List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			BigDecimal accountEntryPrice = actinfos.stream()
					.map(a -> a.getAmount())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			Logger.verifyEquals(needPayAmount,
					accountEntryPrice.divide(new BigDecimal(-1), 2, 4),
					"验证账户资金订单支付流水金额");

			// 交易表
			List<Map> ymtTradinginfoList = database
					.selectTradinginfoByTradingId(Integer
							.valueOf(thirdTradingId));

			Logger.comment("验证ymt_tradinginfo表");

			Logger.verifyEquals(needPayAmount.subtract(blanceAmout),
					(BigDecimal) ymtTradinginfoList.get(0).get("fAmount"),
					"验证fAmount");
			Logger.verifyEquals(needPayAmount, (BigDecimal) ymtTradinginfoList
					.get(0).get("fPayableAmount"), "验证fPayableAmount");
			Logger.verifyEquals(2,
					(Integer) ymtTradinginfoList.get(0).get("iTradingStatus"),
					"验证iTradingStatus");
			// 校验
			for (int i = 0; i < orders.size(); i++) {

				int orderId = orders.get(i).getOrderId();

				// ymt_orderpay 表
				List<Map> ymtOrderPay = database.selectOrderPay(orderId);;
				// 订单表
				List<Map> ymtOrders = database.selectOrderByOderId(orderId);
				// 订单资金表
				List<Map> ymtOrderStateList = database
						.selectOrderStateByOderId(orderId);

				// 当前子订单需要支付的金额
				needPayAmount = new OrderCallService()
						.getNeedPrePayAmountOfCash(orderId);
				Logger.comment("验证Ymt_Orders表");

				Logger.verifyEquals(Integer.valueOf(thirdTradingId),
						(Integer) ymtOrders.get(0).get("iTradingId"),
						"验证iTradingId");

				Logger.verifyEquals(2,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.comment("验证ymt_orderstate表");
				Logger.verifyEquals(
						needPayAmount,
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfCash"), "验证fPaidAmountOfCash");
				Logger.verifyEquals(
						needPayAmount.subtract(blanceAmout),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfThirdParty"),
						"验证fPaidAmountOfThirdParty");
				Logger.verifyEquals(
						blanceAmout.setScale(2),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfYmtAccount"),
						"验证fPaidAmountOfYmtAccount");

				Logger.comment("验证ymt_orderpay表");
				Logger.verifyEquals(Integer.valueOf(thirdTradingId),
						(Integer) ymtOrderPay.get(0).get("iTradingId"),
						"验证iTradingId");
				Logger.verifyEquals(2,
						(Integer) ymtOrderPay.get(0).get("iPayType"),
						"验证iPayType");
				Logger.verifyEquals(needPayAmount, (BigDecimal) ymtOrderPay
						.get(0).get("fAmount"), "验证fAmount");
				Logger.verifyEquals(0,
						(Integer) ymtOrderPay.get(0).get("iStatus"),
						"验证iStatus");
				Logger.verifyEquals("支付成功_第三方回调", (String) ymtOrderPay.get(0)
						.get("sMemo"), "验证sMemo");
				Logger.verifyEquals(0,
						(Integer) ymtOrderPay.get(0).get("iAccountingNum"),
						"验证iAccountingNum");
				Logger.verifyEquals("操作成功！",
						(String) ymtOrderPay.get(0).get("sAccountingMessage"),
						"验证sAccountingMessage");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderPayCallBack_006() {
		Logger.start(true, "一笔交易里有多个订单,全款第三方微信支付,,第三方支付通知成功");
		try {
			DefaultWapper database = new DefaultWapper();

			OrderCallService orderCallService = new OrderCallService();
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			List<Order> orders = placeOrderResp.getOrderList();

			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal needPayAmount = placeOrderResp.getPayAmount();// 支付金额

			Logger.comment("前置数据准备结束");

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO.setScale(2);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "15";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 查询支付指令
			HashMap paymentInstruction = new HashMap();
			paymentInstruction = new DefaultWapper()
					.selectPaymentInstructionByNewtradingId(String
							.valueOf(thirdTradingId));

			String trackId = (String) paymentInstruction.get("id");
			orderPayCallBackBean.setAppId("1");
			orderPayCallBackBean.setBizCode("3");
			orderPayCallBackBean.setCurrency("CNY");
			orderPayCallBackBean.setMemo("autotest");
			orderPayCallBackBean.setTradingId(String.valueOf(thirdTradingId));
			orderPayCallBackBean.setPaymentId("radamnumber");
			// 此接口的价格不用传，因为接口不会按照这个参数进行支付。
			orderPayCallBackBean.setPayPrice("price");
			orderPayCallBackBean.setPayTime("2015-09-09T22:53:22");
			orderPayCallBackBean.setSignMethod("");
			orderPayCallBackBean.setTraceId(trackId);
			orderPayCallBackBean.setInstPaymentId("radamInstPaymentId");
			orderPayCallBackBean.setInternalUserId("internaluseid");
			orderPayCallBackBean.setExternalUserId("radamuserId");
			orderPayCallBackBean.setPayChannel("Alipay");
			orderPayCallBackBean.setPayType("type");
			orderPayCallBackBean.setVersion(1);
			// 发送请求
			orderPayCallBackCall.setData(orderPayCallBackBean);
			orderPayCallBackCall.callService();

			// 支付后金额
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(tradingId));

			List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			BigDecimal accountEntryPrice = actinfos.stream()
					.map(a -> a.getAmount())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			Logger.verifyEquals(needPayAmount,
					accountEntryPrice.divide(new BigDecimal(-1), 2, 4),
					"验证账户资金订单支付流水金额");

			// 交易表
			List<Map> ymtTradinginfoList = database
					.selectTradinginfoByTradingId(Integer
							.valueOf(thirdTradingId));
			Logger.comment("验证ymt_tradinginfo表");
			Logger.verifyEquals(needPayAmount.subtract(blanceAmout),
					(BigDecimal) ymtTradinginfoList.get(0).get("fAmount"),
					"验证fAmount");
			Logger.verifyEquals(needPayAmount, (BigDecimal) ymtTradinginfoList
					.get(0).get("fPayableAmount"), "验证fPayableAmount");
			Logger.verifyEquals(2,
					(Integer) ymtTradinginfoList.get(0).get("iTradingStatus"),
					"验证iTradingStatus");
			// 校验
			for (int i = 0; i < orders.size(); i++) {

				int orderId = orders.get(i).getOrderId();
				// ymt_orderpay 表
				List<Map> ymtOrderPay = database.selectOrderPay(orderId);;

				// 订单表
				List<Map> ymtOrders = database.selectOrderByOderId(orderId);
				// 订单资金表
				List<Map> ymtOrderStateList = database
						.selectOrderStateByOderId(orderId);
				// 当前子订单需要支付的金额
				needPayAmount = new OrderCallService()
						.getNeedPrePayAmountOfCash(orderId);
				Logger.comment("验证Ymt_Orders表");
				Logger.verifyEquals(Integer.valueOf(thirdTradingId),
						(Integer) ymtOrders.get(0).get("iTradingId"),
						"验证iTradingId");
				Logger.verifyEquals(2,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.comment("验证ymt_orderstate表");
				Logger.verifyEquals(
						needPayAmount,
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfCash"), "验证fPaidAmountOfCash");
				Logger.verifyEquals(
						needPayAmount.subtract(blanceAmout),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfThirdParty"),
						"验证fPaidAmountOfThirdParty");
				Logger.verifyEquals(
						blanceAmout.setScale(2),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfYmtAccount"),
						"验证fPaidAmountOfYmtAccount");
				Logger.comment("验证ymt_orderpay表");
				Logger.verifyEquals(Integer.valueOf(thirdTradingId),
						(Integer) ymtOrderPay.get(0).get("iTradingId"),
						"验证iTradingId");
				Logger.verifyEquals(2,
						(Integer) ymtOrderPay.get(0).get("iPayType"),
						"验证iPayType");
				Logger.verifyEquals(needPayAmount, (BigDecimal) ymtOrderPay
						.get(0).get("fAmount"), "验证fAmount");
				Logger.verifyEquals(0,
						(Integer) ymtOrderPay.get(0).get("iStatus"),
						"验证iStatus");
				Logger.verifyEquals("支付成功_第三方回调", (String) ymtOrderPay.get(0)
						.get("sMemo"), "验证sMemo");
				Logger.verifyEquals(0,
						(Integer) ymtOrderPay.get(0).get("iAccountingNum"),
						"验证iAccountingNum");
				Logger.verifyEquals("操作成功！",
						(String) ymtOrderPay.get(0).get("sAccountingMessage"),
						"验证sAccountingMessage");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderPayCallBack_007() {
		Logger.start(true, "一笔交易里有多个订单,余额+第三方混合支付,第三方支付通知成功");
		try {
			DefaultWapper database = new DefaultWapper();
			OrderCallService orderCallService = new OrderCallService();
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			List<Order> orders = placeOrderResp.getOrderList();

			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalNeedPayAmout = placeOrderResp.getPayAmount();// 支付金额

			Logger.comment("前置数据准备结束");

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(46).setScale(2);
			BigDecimal thirdPayAmout = totalNeedPayAmout.subtract(blanceAmout);

			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 查询支付指令
			HashMap paymentInstruction = new HashMap();
			paymentInstruction = new DefaultWapper()
					.selectPaymentInstructionByNewtradingId(String
							.valueOf(thirdTradingId));
			String trackId = (String) paymentInstruction.get("id");
			orderPayCallBackBean.setAppId("1");
			orderPayCallBackBean.setBizCode("3");
			orderPayCallBackBean.setCurrency("CNY");
			orderPayCallBackBean.setMemo("autotest");
			orderPayCallBackBean.setTradingId(String.valueOf(thirdTradingId));
			orderPayCallBackBean.setPaymentId("radamnumber");
			// 此接口的价格不用传，因为接口不会按照这个参数进行支付。
			orderPayCallBackBean.setPayPrice("price");
			orderPayCallBackBean.setPayTime("2015-09-09T22:53:22");
			orderPayCallBackBean.setSignMethod("");
			orderPayCallBackBean.setTraceId(trackId);
			orderPayCallBackBean.setInstPaymentId("radamInstPaymentId");
			orderPayCallBackBean.setInternalUserId("internaluseid");
			orderPayCallBackBean.setExternalUserId("radamuserId");
			orderPayCallBackBean.setPayChannel("Alipay");
			orderPayCallBackBean.setPayType("type");
			orderPayCallBackBean.setVersion(1);
			// 发送请求
			orderPayCallBackCall.setData(orderPayCallBackBean);
			orderPayCallBackCall.callService();
			// 支付后金额
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(tradingId));
			List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			BigDecimal accountEntryPrice = actinfos.stream()
					.map(a -> a.getAmount())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			Logger.verifyEquals(totalNeedPayAmout,
					accountEntryPrice.divide(new BigDecimal(-1), 2, 4),
					"验证账户资金订单支付流水金额");
			// 交易表
			List<Map> ymtTradinginfoList = database
					.selectTradinginfoByTradingId(Integer
							.valueOf(thirdTradingId));
			Logger.comment("验证ymt_tradinginfo表");
			Logger.verifyEquals(totalNeedPayAmout.subtract(blanceAmout),
					(BigDecimal) ymtTradinginfoList.get(0).get("fAmount"),
					"验证fAmount");
			Logger.verifyEquals(totalNeedPayAmout,
					(BigDecimal) ymtTradinginfoList.get(0)
							.get("fPayableAmount"), "验证fPayableAmount");
			Logger.verifyEquals(2,
					(Integer) ymtTradinginfoList.get(0).get("iTradingStatus"),
					"验证iTradingStatus");

			BigDecimal tempThirdPayAmout = BigDecimal.ZERO;

			// 校验
			for (int i = 0; i < orders.size(); i++) {

				int orderId = orders.get(i).getOrderId();
				// ymt_orderpay 表
				List<Map> ymtOrderPay = database.selectOrderPay(orderId);;
				// 订单表
				List<Map> ymtOrders = database.selectOrderByOderId(orderId);
				// 订单资金表
				List<Map> ymtOrderStateList = database
						.selectOrderStateByOderId(orderId);
				// 当前子订单需要支付的金额
				BigDecimal orderNeedPayAmout = new OrderCallService()
						.getNeedPrePayAmountOfCash(orderId);
				Logger.comment("验证Ymt_Orders表");
				Logger.verifyEquals(Integer.valueOf(thirdTradingId),
						(Integer) ymtOrders.get(0).get("iTradingId"),
						"验证iTradingId");
				Logger.verifyEquals(2,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");

				BigDecimal orderThirdPayAmout = BigDecimal.ZERO;
				// 第三方支付的金额，按比例分摊到各个订单上
				if (i == orders.size() - 1) {
					orderThirdPayAmout = thirdPayAmout
							.subtract(tempThirdPayAmout);
				} else {
					orderThirdPayAmout = orderNeedPayAmout.multiply(
							thirdPayAmout).divide(totalNeedPayAmout, 2,
							BigDecimal.ROUND_HALF_UP);
				}
				tempThirdPayAmout = orderThirdPayAmout.add(tempThirdPayAmout);

				Logger.comment("验证ymt_orderstate表");
				Logger.verifyEquals(
						orderNeedPayAmout,
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfCash"), "验证fPaidAmountOfCash");
				Logger.verifyEquals(
						orderThirdPayAmout.setScale(2),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfThirdParty"),
						"验证fPaidAmountOfThirdParty");
				Logger.verifyEquals(
						orderNeedPayAmout.subtract(orderThirdPayAmout),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfYmtAccount"),
						"验证fPaidAmountOfYmtAccount");
				Logger.comment("验证ymt_orderpay表");
				Logger.verifyEquals(Integer.valueOf(thirdTradingId),
						(Integer) ymtOrderPay.get(0).get("iTradingId"),
						"验证iTradingId");
				Logger.verifyEquals(2,
						(Integer) ymtOrderPay.get(0).get("iPayType"),
						"验证iPayType");
				Logger.verifyEquals(orderNeedPayAmout, (BigDecimal) ymtOrderPay
						.get(0).get("fAmount"), "验证fAmount");
				Logger.verifyEquals(0,
						(Integer) ymtOrderPay.get(0).get("iStatus"),
						"验证iStatus");
				Logger.verifyEquals("支付成功_第三方回调", (String) ymtOrderPay.get(0)
						.get("sMemo"), "验证sMemo");
				Logger.verifyEquals(0,
						(Integer) ymtOrderPay.get(0).get("iAccountingNum"),
						"验证iAccountingNum");
				Logger.verifyEquals("操作成功！",
						(String) ymtOrderPay.get(0).get("sAccountingMessage"),
						"验证sAccountingMessage");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderPayCallBack_008() {
		Logger.start(true, "全款第三方支付,所有子订单全部取消,走快速退款");
		try {
			DefaultWapper database = new DefaultWapper();
			OrderCallService orderCallService = new OrderCallService();
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			List<Order> orders = placeOrderResp.getOrderList();

			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalNeedPayAmout = placeOrderResp.getPayAmount();// 支付金额

			Logger.comment("前置数据准备结束");

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO.setScale(2);
			BigDecimal thirdPayAmout = totalNeedPayAmout.subtract(blanceAmout);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);

			// 取消所有子单
			int orderId1 = orders.get(0).getOrderId();
			int orderId2 = orders.get(1).getOrderId();

			orderCallService.cancelOrder(orderId1, userId);
			orderCallService.cancelOrder(orderId2, userId);

			// 支付网关回调
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalNeedPayAmout.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			// 退款回调
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalNeedPayAmout.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			// 支付后金额

			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(thirdTradingId));
			List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			BigDecimal accountEntryPrice = actinfos.stream()
					.map(a -> a.getAmount())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			Logger.verifyEquals(BigDecimal.ZERO.setScale(2), accountEntryPrice,
					"验证账户资金流水金额");

			// 交易表
			List<Map> ymtTradinginfoList = database
					.selectTradinginfoByTradingId(Integer
							.valueOf(thirdTradingId));
			Logger.comment("验证ymt_tradinginfo表");
			Logger.verifyEquals(totalNeedPayAmout.subtract(blanceAmout),
					(BigDecimal) ymtTradinginfoList.get(0).get("fAmount"),
					"验证fAmount");
			Logger.verifyEquals(totalNeedPayAmout,
					(BigDecimal) ymtTradinginfoList.get(0)
							.get("fPayableAmount"), "验证fPayableAmount");
			Logger.verifyEquals(2,
					(Integer) ymtTradinginfoList.get(0).get("iTradingStatus"),
					"验证iTradingStatus");

			BigDecimal tempThirdPayAmout = BigDecimal.ZERO;
			// 校验
			for (int i = 0; i < orders.size(); i++) {
				int orderId = orders.get(i).getOrderId();
				// ymt_orderpay 表
				List<Map> ymtOrderPay = database.selectOrderPay(orderId);;
				// 订单表
				List<Map> ymtOrders = database.selectOrderByOderId(orderId);
				// 订单资金表
				List<Map> ymtOrderStateList = database
						.selectOrderStateByOderId(orderId);
				// 当前子订单需要支付的金额
				BigDecimal orderNeedPayAmout = new OrderCallService()
						.getNeedPrePayAmountOfCash(orderId);
				Logger.comment("验证Ymt_Orders表");
				Logger.verifyEquals(null,
						(Integer) ymtOrders.get(0).get("iTradingId"),
						"验证iTradingId");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.comment("验证ymt_orderstate表");
				Logger.verifyEquals(
						BigDecimal.ZERO.setScale(2),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfCash"), "验证fPaidAmountOfCash");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderStateList.get(0)
						.get("fPaidAmountOfThirdParty"),
						"验证fPaidAmountOfThirdParty");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderStateList.get(0)
						.get("fPaidAmountOfYmtAccount"),
						"验证fPaidAmountOfYmtAccount");
				Logger.verifyEquals(
						BigDecimal.ZERO.setScale(2),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderStateList.get(0)
						.get("fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
				Logger.comment("验证ymt_orderpay表");
				Logger.verifyEquals(tradingId, (Integer) ymtOrderPay.get(0)
						.get("iTradingId"), "验证iTradingId");
				Logger.verifyEquals(2,
						(Integer) ymtOrderPay.get(0).get("iPayType"),
						"验证iPayType");
				Logger.verifyEquals(orderNeedPayAmout, (BigDecimal) ymtOrderPay
						.get(0).get("fAmount"), "验证fAmount");
				Logger.verifyEquals(-1,
						(Integer) ymtOrderPay.get(0).get("iStatus"),
						"验证iStatus");
				Logger.verifyEquals(null,
						(String) ymtOrderPay.get(0).get("sMemo"), "验证sMemo");
				Logger.verifyEquals(0,
						(Integer) ymtOrderPay.get(0).get("iAccountingNum"),
						"验证iAccountingNum");
				Logger.verifyEquals(null,
						(String) ymtOrderPay.get(0).get("sAccountingMessage"),
						"验证sAccountingMessage");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderPayCallBack_009() {
		Logger.start(true, "全款第三方支付,子订单部分取消");
		try {
			DefaultWapper database = new DefaultWapper();
			OrderCallService orderCallService = new OrderCallService();
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			List<Order> orders = placeOrderResp.getOrderList();

			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalNeedPayAmout = placeOrderResp.getPayAmount();// 支付金额

			Logger.comment("前置数据准备结束");

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO.setScale(2);
			BigDecimal thirdPayAmout = totalNeedPayAmout.subtract(blanceAmout);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 取消子单
			int orderId1 = orders.get(0).getOrderId();
			int orderId2 = orders.get(1).getOrderId();
			orderCallService.cancelOrder(orderId1, userId);
			// orderCallService.cancelOrder(orderId2, userId);
			// 支付网关回调
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalNeedPayAmout.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			// 支付后金额
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(tradingId));
			List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			BigDecimal accountEntryPrice = actinfos.stream()
					.map(a -> a.getAmount())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			Logger.verifyEquals(
					orderCallService.getNeedPrePayAmountOfCash(orderId2),
					accountEntryPrice.divide(new BigDecimal(-1), 2, 4),
					"验证账户资金订单支付流水金额");

			// 交易表
			List<Map> ymtTradinginfoList = database
					.selectTradinginfoByTradingId(Integer
							.valueOf(thirdTradingId));
			Logger.comment("验证ymt_tradinginfo表");
			Logger.verifyEquals(totalNeedPayAmout,
					(BigDecimal) ymtTradinginfoList.get(0).get("fAmount"),
					"验证fAmount");
			Logger.verifyEquals(totalNeedPayAmout,
					(BigDecimal) ymtTradinginfoList.get(0)
							.get("fPayableAmount"), "验证fPayableAmount");
			Logger.verifyEquals(2,
					(Integer) ymtTradinginfoList.get(0).get("iTradingStatus"),
					"验证iTradingStatus");
			BigDecimal tempThirdPayAmout = BigDecimal.ZERO;
			// 校验
			int orderId = orderId2;
			// ymt_orderpay 表
			List<Map> ymtOrderPay = database.selectOrderPay(orderId);;
			// 订单表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 订单资金表
			List<Map> ymtOrderStateList = database
					.selectOrderStateByOderId(orderId);
			// 当前子订单需要支付的金额
			BigDecimal orderNeedPayAmout = new OrderCallService()
					.getNeedPrePayAmountOfCash(orderId);
			Logger.comment("验证Ymt_Orders表");
			Logger.verifyEquals(thirdTradingId,
					(Integer) ymtOrders.get(0).get("iTradingId"),
					"验证iTradingId");
			Logger.verifyEquals(2,
					(Integer) ymtOrders.get(0).get("iTradingStatus"),
					"验证iTradingStatus");
			Logger.comment("验证ymt_orderstate表");
			Logger.verifyEquals(
					orderNeedPayAmout,
					(BigDecimal) ymtOrderStateList.get(0).get(
							"fPaidAmountOfCash"), "验证fPaidAmountOfCash");
			Logger.verifyEquals(
					orderNeedPayAmout.subtract(blanceAmout),
					(BigDecimal) ymtOrderStateList.get(0).get(
							"fPaidAmountOfThirdParty"),
					"验证fPaidAmountOfThirdParty");
			Logger.verifyEquals(blanceAmout, (BigDecimal) ymtOrderStateList
					.get(0).get("fPaidAmountOfYmtAccount"),
					"验证fPaidAmountOfYmtAccount");
			Logger.verifyEquals(
					BigDecimal.ZERO.setScale(2),
					(BigDecimal) ymtOrderStateList.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(null, (BigDecimal) ymtOrderStateList.get(0)
					.get("fRefundedPaidAmountToThirdParty"),
					"验证fRefundedPaidAmountToThirdParty");
			Logger.comment("验证ymt_orderpay表");
			Logger.verifyEquals(thirdTradingId, (Integer) ymtOrderPay.get(0)
					.get("iTradingId"), "验证iTradingId");
			Logger.verifyEquals(2,
					(Integer) ymtOrderPay.get(0).get("iPayType"), "验证iPayType");
			Logger.verifyEquals(orderNeedPayAmout, (BigDecimal) ymtOrderPay
					.get(0).get("fAmount"), "验证fAmount");
			Logger.verifyEquals(0, (Integer) ymtOrderPay.get(0).get("iStatus"),
					"验证iStatus");
			Logger.verifyEquals("支付成功_第三方回调",
					(String) ymtOrderPay.get(0).get("sMemo"), "验证sMemo");
			Logger.verifyEquals(0,
					(Integer) ymtOrderPay.get(0).get("iAccountingNum"),
					"验证iAccountingNum");
			Logger.verifyEquals("操作成功！",
					(String) ymtOrderPay.get(0).get("sAccountingMessage"),
					"验证sAccountingMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderPayCallBack_010() {
		Logger.start(true, "余额+第三方组合支付,所有子订单全部取消,走快速退款");
		try {
			DefaultWapper database = new DefaultWapper();
			OrderCallService orderCallService = new OrderCallService();
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			List<Order> orders = placeOrderResp.getOrderList();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalNeedPayAmout = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(46).setScale(2);
			BigDecimal thirdPayAmout = totalNeedPayAmout.subtract(blanceAmout);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 取消所有子单
			int orderId1 = orders.get(0).getOrderId();
			int orderId2 = orders.get(1).getOrderId();
			orderCallService.cancelOrder(orderId1, userId);
			orderCallService.cancelOrder(orderId2, userId);
			// 支付网关回调
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalNeedPayAmout.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			// 退款回调
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalNeedPayAmout.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			// 支付后金额
			Map act = new HashMap();
			// act.put("bizno", String.valueOf(orderId));
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(thirdTradingId));

			List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			BigDecimal accountEntryPrice = actinfos.stream()
					.map(a -> a.getAmount())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			Logger.verifyEquals(BigDecimal.ZERO.setScale(2), accountEntryPrice,
					"验证账户金额");

			// 交易表
			List<Map> ymtTradinginfoList = database
					.selectTradinginfoByTradingId(Integer
							.valueOf(thirdTradingId));
			Logger.comment("验证ymt_tradinginfo表");
			Logger.verifyEquals(totalNeedPayAmout.subtract(blanceAmout),
					(BigDecimal) ymtTradinginfoList.get(0).get("fAmount"),
					"验证fAmount");
			Logger.verifyEquals(totalNeedPayAmout,
					(BigDecimal) ymtTradinginfoList.get(0)
							.get("fPayableAmount"), "验证fPayableAmount");
			Logger.verifyEquals(2,
					(Integer) ymtTradinginfoList.get(0).get("iTradingStatus"),
					"验证iTradingStatus");

			// 校验
			for (int i = 0; i < orders.size(); i++) {
				int orderId = orders.get(i).getOrderId();
				// ymt_orderpay 表
				List<Map> ymtOrderPay = database.selectOrderPay(orderId);;
				// 订单表
				List<Map> ymtOrders = database.selectOrderByOderId(orderId);
				// 订单资金表
				List<Map> ymtOrderStateList = database
						.selectOrderStateByOderId(orderId);
				// 当前子订单需要支付的金额
				BigDecimal orderNeedPayAmout = new OrderCallService()
						.getNeedPrePayAmountOfCash(orderId);
				Logger.comment("验证Ymt_Orders表");
				Logger.verifyEquals(null,
						(Integer) ymtOrders.get(0).get("iTradingId"),
						"验证iTradingId");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.comment("验证ymt_orderstate表");
				Logger.verifyEquals(
						BigDecimal.ZERO.setScale(2),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfCash"), "验证fPaidAmountOfCash");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderStateList.get(0)
						.get("fPaidAmountOfThirdParty"),
						"验证fPaidAmountOfThirdParty");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderStateList.get(0)
						.get("fPaidAmountOfYmtAccount"),
						"验证fPaidAmountOfYmtAccount");
				Logger.verifyEquals(
						BigDecimal.ZERO.setScale(2),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderStateList.get(0)
						.get("fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
				Logger.comment("验证ymt_orderpay表");
				Logger.verifyEquals(tradingId, (Integer) ymtOrderPay.get(0)
						.get("iTradingId"), "验证iTradingId");
				Logger.verifyEquals(2,
						(Integer) ymtOrderPay.get(0).get("iPayType"),
						"验证iPayType");
				Logger.verifyEquals(orderNeedPayAmout, (BigDecimal) ymtOrderPay
						.get(0).get("fAmount"), "验证fAmount");
				Logger.verifyEquals(-1,
						(Integer) ymtOrderPay.get(0).get("iStatus"),
						"验证iStatus");
				Logger.verifyEquals(null,
						(String) ymtOrderPay.get(0).get("sMemo"), "验证sMemo");
				Logger.verifyEquals(0,
						(Integer) ymtOrderPay.get(0).get("iAccountingNum"),
						"验证iAccountingNum");
				Logger.verifyEquals(null,
						(String) ymtOrderPay.get(0).get("sAccountingMessage"),
						"验证sAccountingMessage");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderPayCallBack_011() {
		Logger.start(true, "余额+第三方组合支付,子订单部分取消");
		try {
			DefaultWapper database = new DefaultWapper();
			OrderCallService orderCallService = new OrderCallService();
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			List<Order> orders = placeOrderResp.getOrderList();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalNeedPayAmout = placeOrderResp.getPayAmount();// 支付金额

			Logger.comment("前置数据准备结束");

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(46).setScale(2);
			BigDecimal thirdPayAmout = totalNeedPayAmout.subtract(blanceAmout);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);

			int orderId1 = orders.get(0).getOrderId();
			int orderId2 = orders.get(1).getOrderId();
			// 取消子单 orderid1
			orderCallService.cancelOrder(orderId1, userId);
			// 支付网关回调
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalNeedPayAmout.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			// orderId1 取消后，订单应付的金额冲到账户余额
			BigDecimal orderId2PayAmout = orderCallService
					.getNeedPrePayAmountOfCash(orderId2);

			List<YmtAccountEntry> actinfos = new ArrayList<YmtAccountEntry>();
			Map act = new HashMap();
			// act.put("bizno", String.valueOf(orderId));
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(tradingId));

			actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);

			BigDecimal accountEntryPrice = actinfos.stream()
					.map(a -> a.getAmount())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			Logger.verifyEquals(orderId2PayAmout,
					accountEntryPrice.divide(new BigDecimal(-1), 2, 4),
					"验证账户资金订单支付流水金额");

			act.put("originalNo", String.valueOf(thirdTradingId));
			actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);

			accountEntryPrice = actinfos.stream().map(a -> a.getAmount())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			Logger.verifyEquals(thirdPayAmout, accountEntryPrice,
					"验证账户资金定金充值流水金额");

			// 交易表
			List<Map> ymtTradinginfoList = database
					.selectTradinginfoByTradingId(Integer
							.valueOf(thirdTradingId));
			Logger.comment("验证ymt_tradinginfo表");
			Logger.verifyEquals(totalNeedPayAmout.subtract(blanceAmout),
					(BigDecimal) ymtTradinginfoList.get(0).get("fAmount"),
					"验证fAmount");
			Logger.verifyEquals(totalNeedPayAmout,
					(BigDecimal) ymtTradinginfoList.get(0)
							.get("fPayableAmount"), "验证fPayableAmount");
			Logger.verifyEquals(2,
					(Integer) ymtTradinginfoList.get(0).get("iTradingStatus"),
					"验证iTradingStatus");

			BigDecimal tempThirdPayAmout = BigDecimal.ZERO;

			int orderId = orderId2;
			// ymt_orderpay 表
			List<Map> ymtOrderPay = database.selectOrderPay(orderId);;
			// 订单表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 订单资金表
			List<Map> ymtOrderStateList = database
					.selectOrderStateByOderId(orderId);
			// 当前子订单需要支付的金额
			BigDecimal orderNeedPayAmout = orderId2PayAmout;
			Logger.comment("验证Ymt_Orders表");
			Logger.verifyEquals(thirdTradingId,
					(Integer) ymtOrders.get(0).get("iTradingId"),
					"验证iTradingId");
			Logger.verifyEquals(2,
					(Integer) ymtOrders.get(0).get("iTradingStatus"),
					"验证iTradingStatus");
			Logger.comment("验证ymt_orderstate表");
			Logger.verifyEquals(
					orderNeedPayAmout,
					(BigDecimal) ymtOrderStateList.get(0).get(
							"fPaidAmountOfCash"), "验证fPaidAmountOfCash");

			BigDecimal thirdPayPart = orderNeedPayAmout;

			Logger.verifyEquals(thirdPayPart, (BigDecimal) ymtOrderStateList
					.get(0).get("fPaidAmountOfThirdParty"),
					"验证fPaidAmountOfThirdParty");
			Logger.verifyEquals(
					BigDecimal.ZERO.setScale(2),
					(BigDecimal) ymtOrderStateList.get(0).get(
							"fPaidAmountOfYmtAccount"),
					"验证fPaidAmountOfYmtAccount");
			Logger.verifyEquals(
					BigDecimal.ZERO.setScale(2),
					(BigDecimal) ymtOrderStateList.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(null, (BigDecimal) ymtOrderStateList.get(0)
					.get("fRefundedPaidAmountToThirdParty"),
					"验证fRefundedPaidAmountToThirdParty");
			Logger.comment("验证ymt_orderpay表");
			Logger.verifyEquals(thirdTradingId, (Integer) ymtOrderPay.get(0)
					.get("iTradingId"), "验证iTradingId");
			Logger.verifyEquals(2,
					(Integer) ymtOrderPay.get(0).get("iPayType"), "验证iPayType");
			Logger.verifyEquals(orderNeedPayAmout, (BigDecimal) ymtOrderPay
					.get(0).get("fAmount"), "验证fAmount");
			Logger.verifyEquals(0, (Integer) ymtOrderPay.get(0).get("iStatus"),
					"验证iStatus");
			Logger.verifyEquals("支付成功_第三方回调",
					(String) ymtOrderPay.get(0).get("sMemo"), "验证sMemo");
			Logger.verifyEquals(0,
					(Integer) ymtOrderPay.get(0).get("iAccountingNum"),
					"验证iAccountingNum");
			Logger.verifyEquals("操作成功！",
					(String) ymtOrderPay.get(0).get("sAccountingMessage"),
					"验证sAccountingMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	// 支付网关后台,手工模拟
	public void Tc_OrderPayCallBack_012() {
		Logger.start(true, "余额+第三方组合支付,所有子订单部分取消,走快速退款,第三方退款失败,转退账户余额");
		try {
			DefaultWapper database = new DefaultWapper();
			OrderCallService orderCallService = new OrderCallService();
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			List<Order> orders = placeOrderResp.getOrderList();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalNeedPayAmout = placeOrderResp.getPayAmount();// 支付金额

			Logger.comment("前置数据准备结束");

			// 支付用户金额
			HashMap<String, Integer> m1 = new HashMap<String, Integer>();
			m1.put("UserId", userId);
			BigDecimal price1 = (BigDecimal) database.selectAccountInfo(m1)
					.get(0).get("fAvailAmount");
			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(46).setScale(2);
			BigDecimal thirdPayAmout = totalNeedPayAmout.subtract(blanceAmout);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 取消所有子单
			int orderId1 = orders.get(0).getOrderId();
			int orderId2 = orders.get(1).getOrderId();
			orderCallService.cancelOrder(orderId1, userId);
			orderCallService.cancelOrder(orderId2, userId);
			// 支付网关回调
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalNeedPayAmout.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			// 退款回调
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalNeedPayAmout.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			// 支付后金额
			BigDecimal price2 = (BigDecimal) database.selectAccountInfo(m1)
					.get(0).get("fAvailAmount");
			Logger.verifyEquals(BigDecimal.ZERO.setScale(2),
					price1.subtract(price2), "验证账户金额");

			// 交易表
			List<Map> ymtTradinginfoList = database
					.selectTradinginfoByTradingId(Integer
							.valueOf(thirdTradingId));
			Logger.comment("验证ymt_tradinginfo表");
			Logger.verifyEquals(totalNeedPayAmout.subtract(blanceAmout),
					(BigDecimal) ymtTradinginfoList.get(0).get("fAmount"),
					"验证fAmount");
			Logger.verifyEquals(totalNeedPayAmout,
					(BigDecimal) ymtTradinginfoList.get(0)
							.get("fPayableAmount"), "验证fPayableAmount");
			Logger.verifyEquals(2,
					(Integer) ymtTradinginfoList.get(0).get("iTradingStatus"),
					"验证iTradingStatus");

			BigDecimal tempThirdPayAmout = BigDecimal.ZERO;
			// 校验
			for (int i = 0; i < orders.size(); i++) {
				int orderId = orders.get(i).getOrderId();
				// ymt_orderpay 表
				List<Map> ymtOrderPay = database.selectOrderPay(orderId);;
				// 订单表
				List<Map> ymtOrders = database.selectOrderByOderId(orderId);
				// 订单资金表
				List<Map> ymtOrderStateList = database
						.selectOrderStateByOderId(orderId);
				// 当前子订单需要支付的金额
				BigDecimal orderNeedPayAmout = new OrderCallService()
						.getNeedPrePayAmountOfCash(orderId);
				Logger.comment("验证Ymt_Orders表");
				Logger.verifyEquals(null,
						(Integer) ymtOrders.get(0).get("iTradingId"),
						"验证iTradingId");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.comment("验证ymt_orderstate表");
				Logger.verifyEquals(
						BigDecimal.ZERO.setScale(2),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfCash"), "验证fPaidAmountOfCash");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderStateList.get(0)
						.get("fPaidAmountOfThirdParty"),
						"验证fPaidAmountOfThirdParty");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderStateList.get(0)
						.get("fPaidAmountOfYmtAccount"),
						"验证fPaidAmountOfYmtAccount");
				Logger.verifyEquals(
						BigDecimal.ZERO.setScale(2),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderStateList.get(0)
						.get("fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
				Logger.comment("验证ymt_orderpay表");
				Logger.verifyEquals(tradingId, (Integer) ymtOrderPay.get(0)
						.get("iTradingId"), "验证iTradingId");
				Logger.verifyEquals(2,
						(Integer) ymtOrderPay.get(0).get("iPayType"),
						"验证iPayType");
				Logger.verifyEquals(orderNeedPayAmout, (BigDecimal) ymtOrderPay
						.get(0).get("fAmount"), "验证fAmount");
				Logger.verifyEquals(-1,
						(Integer) ymtOrderPay.get(0).get("iStatus"),
						"验证iStatus");
				Logger.verifyEquals(null,
						(String) ymtOrderPay.get(0).get("sMemo"), "验证sMemo");
				Logger.verifyEquals(0,
						(Integer) ymtOrderPay.get(0).get("iAccountingNum"),
						"验证iAccountingNum");
				Logger.verifyEquals(null,
						(String) ymtOrderPay.get(0).get("sAccountingMessage"),
						"验证sAccountingMessage");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderPayCallBack_013() {
		Logger.start(true, "第三方支付,重复回调");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			Logger.comment("前置数据准备结束");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 获取支付前账户金额
			DefaultWapper database = new DefaultWapper();
			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO.setScale(2);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 查询支付指令
			HashMap paymentInstruction = new HashMap();
			paymentInstruction = new DefaultWapper()
					.selectPaymentInstructionByNewtradingId(String
							.valueOf(thirdTradingId));
			String trackId = (String) paymentInstruction.get("id");
			orderPayCallBackBean.setAppId("1");
			orderPayCallBackBean.setBizCode("3");
			orderPayCallBackBean.setCurrency("CNY");
			orderPayCallBackBean.setMemo("autotest");
			orderPayCallBackBean.setTradingId(String.valueOf(thirdTradingId));
			orderPayCallBackBean.setPaymentId("radamnumber");
			// 此接口的价格不用传，因为接口不会按照这个参数进行支付。
			orderPayCallBackBean.setPayPrice("price");
			orderPayCallBackBean.setPayTime("2015-09-09T22:53:22");
			orderPayCallBackBean.setSignMethod("");
			orderPayCallBackBean.setTraceId(trackId);
			orderPayCallBackBean.setInstPaymentId("radamInstPaymentId");
			orderPayCallBackBean.setInternalUserId("internaluseid");
			orderPayCallBackBean.setExternalUserId("radamuserId");
			orderPayCallBackBean.setPayChannel("Alipay");
			orderPayCallBackBean.setPayType("type");
			orderPayCallBackBean.setVersion(1);
			// 发送请求
			orderPayCallBackCall.setData(orderPayCallBackBean);
			orderPayCallBackCall.callService();
			Logger.comment("重复请求");
			orderPayCallBackCall.callService();
			Thread.sleep(2000);
			Logger.verifyEquals(ECode.FAILED201,
					orderPayCallBackCall.getCode(), "验证Code");
			Logger.verifyEquals("104", orderPayCallBackCall.getBCode(),
					"验证Code");
			// 支付后金额
			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 2);
			m.put("TraddingId", orderId);
			m.put("ReceiveUserId", sellerId);
			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易状态表");
			Map act = new HashMap();
			act.put("bizno", String.valueOf(orderId));
			act.put("userId", userId);
			// act.put("originalNo", String.valueOf(thirdTradingId2));
			List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			Logger.verifyEquals(totalPrice,
					actinfos.get(0).getAmount()
							.divide(new BigDecimal(-1), 2, 4), "验证账户资金订单支付流水金额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderPayCallBack_014() {
		Logger.start(true, "第三方支付,并发重复回调");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");

			// 获取支付前账户金额
			DefaultWapper database = new DefaultWapper();

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO.setScale(2);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 查询支付指令
			HashMap paymentInstruction = new HashMap();
			paymentInstruction = new DefaultWapper()
					.selectPaymentInstructionByNewtradingId(String
							.valueOf(thirdTradingId));
			String trackId = (String) paymentInstruction.get("id");
			orderPayCallBackBean.setAppId("1");
			orderPayCallBackBean.setBizCode("3");
			orderPayCallBackBean.setCurrency("CNY");
			orderPayCallBackBean.setMemo("autotest");
			orderPayCallBackBean.setTradingId(String.valueOf(thirdTradingId));
			orderPayCallBackBean.setPaymentId("radamnumber");
			// 此接口的价格不用传，因为接口不会按照这个参数进行支付。
			orderPayCallBackBean.setPayPrice("price");
			orderPayCallBackBean.setPayTime("2015-09-09T22:53:22");
			orderPayCallBackBean.setSignMethod("");
			orderPayCallBackBean.setTraceId(trackId);
			orderPayCallBackBean.setInstPaymentId("radamInstPaymentId");
			orderPayCallBackBean.setInternalUserId("internaluseid");
			orderPayCallBackBean.setExternalUserId("radamuserId");
			orderPayCallBackBean.setPayChannel("Alipay");
			orderPayCallBackBean.setPayType("type");
			orderPayCallBackBean.setVersion(1);
			// 发送请求
			orderPayCallBackCall.setData(orderPayCallBackBean);
			CountDownLatch countDownLatch = new CountDownLatch(2);
			new Thread(() -> {
				try {
					orderPayCallBackCall.callService();
					countDownLatch.countDown();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}).start();
			new Thread(() -> {
				try {
					orderPayCallBackCall.callService();
					countDownLatch.countDown();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}).start();

			Thread.sleep(10000);

			HashMap<String, Integer> m = new HashMap<String, Integer>();
			m.put("OrderId", orderId);
			m.put("TradingStatus", 2);
			m.put("TraddingId", orderId);
			m.put("ReceiveUserId", sellerId);
			Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
			Logger.verifyEquals(1, database.selectTradingStatus(m).size(),
					"验证交易状态表");
			Map act = new HashMap();
			act.put("bizno", String.valueOf(orderId));
			act.put("userId", userId);
			// act.put("originalNo", String.valueOf(thirdTradingId2));
			List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			Logger.verifyEquals(totalPrice,
					actinfos.get(0).getAmount()
							.divide(new BigDecimal(-1), 2, 4), "验证账户资金订单支付流水金额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_OrderPayCallBack_015() {
		Logger.start(true, "一笔交易里有多个订单,余额+第三方混合支付,第三方支付通知成功");
		try {
			DefaultWapper database = new DefaultWapper();
			OrderCallService orderCallService = new OrderCallService();
			// 创建订单
			Logger.comment("前置数据准备");

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder3();

			List<Order> orders = placeOrderResp.getOrderList();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalNeedPayAmout = placeOrderResp.getPayAmount();// 支付金额

			Logger.comment("前置数据准备结束");

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(46).setScale(2);
			BigDecimal thirdPayAmout = totalNeedPayAmout.subtract(blanceAmout);

			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 查询支付指令
			HashMap paymentInstruction = new HashMap();
			paymentInstruction = new DefaultWapper()
					.selectPaymentInstructionByNewtradingId(String
							.valueOf(thirdTradingId));
			String trackId = (String) paymentInstruction.get("id");
			orderPayCallBackBean.setAppId("1");
			orderPayCallBackBean.setBizCode("3");
			orderPayCallBackBean.setCurrency("CNY");
			orderPayCallBackBean.setMemo("autotest");
			orderPayCallBackBean.setTradingId(String.valueOf(thirdTradingId));
			orderPayCallBackBean.setPaymentId("radamnumber");
			// 此接口的价格不用传，因为接口不会按照这个参数进行支付。
			orderPayCallBackBean.setPayPrice("price");
			orderPayCallBackBean.setPayTime("2015-09-09T22:53:22");
			orderPayCallBackBean.setSignMethod("");
			orderPayCallBackBean.setTraceId(trackId);
			orderPayCallBackBean.setInstPaymentId("radamInstPaymentId");
			orderPayCallBackBean.setInternalUserId("internaluseid");
			orderPayCallBackBean.setExternalUserId("radamuserId");
			orderPayCallBackBean.setPayChannel("Alipay");
			orderPayCallBackBean.setPayType("type");
			orderPayCallBackBean.setVersion(1);
			// 发送请求
			orderPayCallBackCall.setData(orderPayCallBackBean);
			orderPayCallBackCall.callService();
			// 支付后金额
			Map act = new HashMap();
			act.put("userId", userId);
			act.put("originalNo", String.valueOf(tradingId));
			List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
					.selectAccountEntryByBizNo(act);
			BigDecimal accountEntryPrice = actinfos.stream()
					.map(a -> a.getAmount())
					.reduce(BigDecimal.ZERO, BigDecimal::add);

			Logger.verifyEquals(totalNeedPayAmout,
					accountEntryPrice.divide(new BigDecimal(-1), 2, 4),
					"验证账户资金订单支付流水金额");
			// 交易表
			List<Map> ymtTradinginfoList = database
					.selectTradinginfoByTradingId(Integer
							.valueOf(thirdTradingId));
			Logger.comment("验证ymt_tradinginfo表");
			Logger.verifyEquals(totalNeedPayAmout.subtract(blanceAmout),
					(BigDecimal) ymtTradinginfoList.get(0).get("fAmount"),
					"验证fAmount");
			Logger.verifyEquals(totalNeedPayAmout,
					(BigDecimal) ymtTradinginfoList.get(0)
							.get("fPayableAmount"), "验证fPayableAmount");
			Logger.verifyEquals(2,
					(Integer) ymtTradinginfoList.get(0).get("iTradingStatus"),
					"验证iTradingStatus");

			BigDecimal tempThirdPayAmout = BigDecimal.ZERO;
			// 校验
			for (int i = 0; i < orders.size(); i++) {
				int orderId = orders.get(i).getOrderId();
				// ymt_orderpay 表
				List<Map> ymtOrderPay = database.selectOrderPay(orderId);;
				// 订单表
				List<Map> ymtOrders = database.selectOrderByOderId(orderId);
				// 订单资金表
				List<Map> ymtOrderStateList = database
						.selectOrderStateByOderId(orderId);
				// 当前子订单需要支付的金额
				BigDecimal orderNeedPayAmout = new OrderCallService()
						.getNeedPrePayAmountOfCash(orderId);
				Logger.comment("验证Ymt_Orders表");
				Logger.verifyEquals(Integer.valueOf(thirdTradingId),
						(Integer) ymtOrders.get(0).get("iTradingId"),
						"验证iTradingId");
				Logger.verifyEquals(2,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");

				BigDecimal orderThirdPayAmout = BigDecimal.ZERO;
				// 第三方支付的金额，按比例分摊到各个订单上
				if (i == orders.size() - 1) {

					orderThirdPayAmout = thirdPayAmout
							.subtract(tempThirdPayAmout);
				} else {
					orderThirdPayAmout = orderNeedPayAmout.multiply(
							thirdPayAmout).divide(totalNeedPayAmout, 2,
							BigDecimal.ROUND_HALF_UP);
				}
				tempThirdPayAmout = orderThirdPayAmout.add(tempThirdPayAmout);

				Logger.comment("验证ymt_orderstate表");
				Logger.verifyEquals(
						orderNeedPayAmout,
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfCash"), "验证fPaidAmountOfCash");
				Logger.verifyEquals(
						orderThirdPayAmout.setScale(2),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfThirdParty"),
						"验证fPaidAmountOfThirdParty");
				Logger.verifyEquals(
						orderNeedPayAmout.subtract(orderThirdPayAmout),
						(BigDecimal) ymtOrderStateList.get(0).get(
								"fPaidAmountOfYmtAccount"),
						"验证fPaidAmountOfYmtAccount");
				Logger.comment("验证ymt_orderpay表");
				Logger.verifyEquals(Integer.valueOf(thirdTradingId),
						(Integer) ymtOrderPay.get(0).get("iTradingId"),
						"验证iTradingId");
				Logger.verifyEquals(2,
						(Integer) ymtOrderPay.get(0).get("iPayType"),
						"验证iPayType");
				Logger.verifyEquals(orderNeedPayAmout, (BigDecimal) ymtOrderPay
						.get(0).get("fAmount"), "验证fAmount");
				Logger.verifyEquals(0,
						(Integer) ymtOrderPay.get(0).get("iStatus"),
						"验证iStatus");
				Logger.verifyEquals("支付成功_第三方回调", (String) ymtOrderPay.get(0)
						.get("sMemo"), "验证sMemo");
				Logger.verifyEquals(0,
						(Integer) ymtOrderPay.get(0).get("iAccountingNum"),
						"验证iAccountingNum");
				Logger.verifyEquals("操作成功！",
						(String) ymtOrderPay.get(0).get("sAccountingMessage"),
						"验证sAccountingMessage");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	// 校验第三方支付通知
	private void verifyDb(int tradingId, List<Integer> orderIds,
			BigDecimal needPayAmount, BigDecimal thirdPayAmount) {
		DefaultWapper database = new DefaultWapper();
		for (int i = 0; i < orderIds.size(); i++) {
			int orderId = orderIds.get(i);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 订单商品明细
			List<Map> ymtOrdersInfoList = database
					.selectOrderInfoByOderId(orderId);
			// ymtOrderState 表
			List<Map> ymtOrderState = database
					.selectOrderStateByOderId(orderId);
			// ymt_orderpay 表
			List<Map> ymtOrderPay = database.selectOrderPay(orderId);
			// Ymt_OrderPostPay 表
			List<Map> ymtOrderPostPay = database
					.selectOrderPostPayByOrderId(orderId);
			// 优惠券金额
			BigDecimal couponValue = (BigDecimal) ymtOrders.get(0).get(
					"CouponValue");
			// 商家用户优惠券金额
			BigDecimal sellerCouponValue = (BigDecimal) ymtOrders.get(0).get(
					"fSellerCouponAmount");
			// 平台用户优惠券金额
			BigDecimal ymtCouponValue = (BigDecimal) ymtOrders.get(0).get(
					"fYmtCouponAmount");
			// 查询当前订单需要支付的定金
			BigDecimal orderNeedPayAmount = new OrderCallService()
					.getNeedPrePayAmountOfCash(orderId);

			BigDecimal dtemp = new BigDecimal(0);
			BigDecimal orderThirdParty = new BigDecimal(0);
			BigDecimal rate = orderNeedPayAmount.divide(needPayAmount, 5,
					BigDecimal.ROUND_HALF_DOWN);
			Logger.debug("rate:" + rate);

			if (i == orderIds.size()) {
				orderThirdParty = thirdPayAmount.subtract(dtemp);
			} else {
				orderThirdParty = rate.multiply(thirdPayAmount).divide(
						new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP);
			}

			Logger.comment("验证订单号:" + orderId);
			Logger.comment("验证ymt_order表");
			Logger.verifyEquals(2,
					(Integer) ymtOrders.get(0).get("iTradingStatus"),
					"验证iTradingStatus");
			Logger.comment("验证ymt_orderState表");
			Logger.verifyEquals(1, ymtOrderState.size(), "验证ymt_orderState表");
			Logger.verifyEquals(couponValue, (BigDecimal) ymtOrderState.get(0)
					.get("fPaidAmountOfCoupon"), "验证fPaidAmountOfCoupon");
			// 余额+第三方支付
			Logger.verifyEquals(orderNeedPayAmount, (BigDecimal) ymtOrderState
					.get(0).get("fPaidAmountOfCash"), "验证fPaidAmountOfCash");
			Logger.verifyEquals(sellerCouponValue, (BigDecimal) ymtOrderState
					.get(0).get("fPaidAmountOfSellerCoupon"),
					"验证fPaidAmountOfSellerCoupon");
			Logger.verifyEquals(
					ymtCouponValue,
					(BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfYmtCoupon"),
					"验证fPaidAmountOfYmtCoupon");

			Logger.verifyEquals(
					orderNeedPayAmount.subtract(orderThirdParty),
					(BigDecimal) ymtOrderState.get(0).get(
							"fPaidAmountOfYmtAccount"),
					"验证fPaidAmountOfYmtAccount");
			Logger.verifyEquals(orderThirdParty, (BigDecimal) ymtOrderState
					.get(0).get("fPaidAmountOfThirdParty"),
					"验证fPaidAmountOfThirdParty");

			Logger.comment("验证ymt_orderpay表");
			Logger.verifyEquals(tradingId,
					(Integer) ymtOrderPay.get(0).get("iTradingId"),
					"验证iTradingId");
			Logger.verifyEquals(2,
					(Integer) ymtOrderPay.get(0).get("iPayType"), "验证iPayType");
			Logger.verifyEquals(orderNeedPayAmount, (BigDecimal) ymtOrderPay
					.get(0).get("fAmount"), "验证fAmount");
			Logger.verifyEquals(0, (Integer) ymtOrderPay.get(0).get("iStatus"),
					"验证iStatus");
			Logger.verifyEquals("支付网关回调处理成功",
					(String) ymtOrderPay.get(0).get("sMemo"), "验证sMemo");
			Logger.verifyEquals(0,
					(Integer) ymtOrderPay.get(0).get("iAccountingNum"),
					"验证iAccountingNum");
			Logger.verifyEquals("操作成功！",
					(String) ymtOrderPay.get(0).get("sAccountingMessage"),
					"验证sAccountingMessage");
			dtemp = dtemp.add(orderThirdParty);

		}

		// ymt_tradinginfo 表
		List<Map> ymtTradinginfo = database
				.selectTradinginfoByTradingId(tradingId);
		Logger.comment("验证ymt_tradinginfo表");
		Logger.verifyEquals(thirdPayAmount.divide(new BigDecimal(1), 2, 4),
				(BigDecimal) ymtTradinginfo.get(0).get("fAmount"), "验证fAmount");
		Logger.verifyEquals(2,
				(Integer) ymtTradinginfo.get(0).get("iTradingStatus"),
				"验证iTradingStatus");
		Logger.verifyEquals(needPayAmount, (BigDecimal) ymtTradinginfo.get(0)
				.get("fPayableAmount"), "验证fPayableAmount");
	}

	/*
	 * // 校验第三方补款通知 private void verifyDb2(int tradingId, int orderId,
	 * BigDecimal payAmount, BigDecimal thirdPayAmount) { // 用户支付的余额
	 * DefaultWapper database = new DefaultWapper(); // 订单主表 List<Map> ymtOrders
	 * = database.selectOrderByOderId(orderId); // 订单商品明细 List<Map>
	 * ymtOrdersInfoList = database.selectOrderInfoByOderId(orderId); //
	 * ymt_tradinginfo 表 List<Map> ymtTradinginfo =
	 * database.selectTradinginfoByTradingId(tradingId); // ymtOrderState 表
	 * List<Map> ymtOrderState = database.selectOrderStateByOderId(orderId); //
	 * Ymt_OrderPostPay 表 List<Map> ymtOrderPostPay =
	 * database.selectOrderPostPayByOrderId(orderId); // 需要支付的定金 BigDecimal
	 * needPayAmount1 = new
	 * OrderCallService().getNeedPrePayAmountOfCash(orderId); // 优惠券金额
	 * BigDecimal couponValue = (BigDecimal)
	 * ymtOrders.get(0).get("CouponValue"); // 商家用户优惠券金额 BigDecimal
	 * sellerCouponValue = (BigDecimal)
	 * ymtOrders.get(0).get("fSellerCouponAmount"); // 平台用户优惠券金额 BigDecimal
	 * ymtCouponValue = (BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount");
	 * 
	 * Logger.comment("验证订单号:" + orderId); Logger.comment("验证ymt_order表");
	 * Logger.verifyEquals( 17, (Integer)
	 * ymtOrders.get(0).get("iTradingStatus"), "验证iTradingStatus");
	 * 
	 * Logger.comment("验证ymt_orderState表"); Logger.verifyEquals(1,
	 * ymtOrderState.size(), "验证ymt_orderState表"); Logger.verifyEquals(
	 * couponValue, (BigDecimal)
	 * ymtOrderState.get(0).get("fPaidAmountOfCoupon"),
	 * "验证fPaidAmountOfCoupon"); // 补款支付总额 Logger.verifyEquals(
	 * payAmount.add(thirdPayAmount), (BigDecimal)
	 * ymtOrderState.get(0).get("fPostPaidAmountOfCash"),
	 * "验证fPostPaidAmountOfCash"); Logger.verifyEquals( sellerCouponValue,
	 * (BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfSellerCoupon"),
	 * "验证fPaidAmountOfSellerCoupon"); Logger.verifyEquals( ymtCouponValue,
	 * (BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfYmtCoupon"),
	 * "验证fPaidAmountOfYmtCoupon"); // 定金付款ymt余额 Logger.verifyEquals(
	 * needPayAmount1, (BigDecimal)
	 * ymtOrderState.get(0).get("fPaidAmountOfYmtAccount"),
	 * "验证fPaidAmountOfYmtAccount"); // 定金付款第三方金额 Logger.verifyEquals(
	 * BigDecimal.ZERO.divide(new BigDecimal(1), 2, 4), (BigDecimal)
	 * ymtOrderState.get(0).get("fPaidAmountOfThirdParty"),
	 * "验证fPaidAmountOfThirdParty"); // 补款付款ymt余额 Logger.verifyEquals(
	 * payAmount, (BigDecimal)
	 * ymtOrderState.get(0).get("fPostPaidAmountOfYmtAccount"),
	 * "验证fPostPaidAmountOfYmtAccount"); // 补款付款第三方金额 Logger.verifyEquals(
	 * thirdPayAmount.divide(new BigDecimal(1), 2, 4), (BigDecimal)
	 * ymtOrderState.get(0).get("fPostPaidAmountOfThirdParty"),
	 * "验证fPostPaidAmountOfThirdParty");
	 * 
	 * }
	 */

}
